package com.shop2cn.iapi.subscription.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.subscription.parameter.MchChargeConfigDto;
import com.shop2cn.iapi.subscription.parameter.SetMchChargeConfigBean;
import com.shop2cn.iapi.subscription.service.SetMchChargeConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.chargeconfig;
import com.ymttest.database.model.godmch.chargeconfigExample;
import com.ymttest.database.sqlwapper.godmch.chargeconfigWapper;
/**
*设置商家功能付费白名单Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetMchChargeConfig{
	private static SetMchChargeConfigBean bean;
	private static SetMchChargeConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商家功能付费白名单Test");
	}

	@Before
	public void caseUp() {
		bean=new SetMchChargeConfigBean();
		call=new SetMchChargeConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	/**
	 * 白名单表：godmch:ChargeConfig
	 */
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetMchChargeConfig_001() {
		Logger.start(true,"设置线下付款白名单商户，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			bean.setMchId(mchid);
			bean.setMchChargeConfigList(Arrays.asList(new MchChargeConfigDto(4,true)));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getString("code"), "验证code");
			//ChargeConfigWapper
			chargeconfigWapper chargeWapper=new chargeconfigWapper();
			chargeconfigExample chargeExample=new chargeconfigExample();
			chargeExample.createCriteria().andMchIdEqualTo(bean.getMchId());
			List<chargeconfig> charges=chargeWapper.selectByExample(chargeExample);
			Logger.verifyEquals(1, charges.size(), "验证白名单ChargeConfig有数据");
			Logger.verifyEquals(true, charges.get(0).getOfflinepay(), "验证白名单ChargeConfig表中的Offlinepay有数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetMchChargeConfig_002() {
		Logger.start(true,"设置线下付款与直播白名单商户，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			bean.setMchId(mchid);
			bean.setMchChargeConfigList(Arrays.asList(new MchChargeConfigDto(4,true),new MchChargeConfigDto(0,true)));
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getString("code"), "验证code");
			//ChargeConfigWapper
			chargeconfigWapper chargeWapper=new chargeconfigWapper();
			chargeconfigExample chargeExample=new chargeconfigExample();
			chargeExample.createCriteria().andMchIdEqualTo(bean.getMchId());
			List<chargeconfig> charges=chargeWapper.selectByExample(chargeExample);
			Logger.verifyEquals(1, charges.size(), "验证白名单ChargeConfig有数据");
			Logger.verifyEquals(true, charges.get(0).getOfflinepay(), "验证白名单ChargeConfig表中的Offlinepay=true");
			
			Logger.verifyEquals(true, charges.get(0).getLiveVideo(), "验证白名单ChargeConfig表中的LiveVideo=true");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetMchChargeConfig_003() {
		Logger.start(true,"幂等验证");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			bean.setMchId(mchid);
			bean.setMchChargeConfigList(Arrays.asList(new MchChargeConfigDto(4,true)));
			call.setData(bean);
			call.callService();			
			call.callService();			
			Logger.verifyEquals("200", call.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetMchChargeConfig_004() {
		Logger.start(true,"设置线下付款白名单商户-自营商品套餐，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			bean.setMchId(mchid);
			bean.setMchChargeConfigList(Arrays.asList(new MchChargeConfigDto(4,true),new MchChargeConfigDto(6,true)));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getString("code"), "验证code");
			//ChargeConfigWapper
			chargeconfigWapper chargeWapper=new chargeconfigWapper();
			chargeconfigExample chargeExample=new chargeconfigExample();
			chargeExample.createCriteria().andMchIdEqualTo(bean.getMchId());
			List<chargeconfig> charges=chargeWapper.selectByExample(chargeExample);
			Logger.verifyEquals(1, charges.size(), "验证白名单ChargeConfig有数据");
			Logger.verifyEquals(true, charges.get(0).getOfflinepay(), "验证白名单ChargeConfig表中的Offlinepay有数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}